﻿namespace Collections;

public class DictionaryItems
{
    public void MyDictionary()
    {
        Dictionary<int, string> employees = new Dictionary<int, string>()
        {
            {
                101, "Scott"
            },
            {
                102, "Sky"
            },
            {
                103, "Allen"
            }
        };
        // foreach loop for dictionary
        foreach (KeyValuePair<int, string> item in employees)
        {
            Console.WriteLine(item.Key + "-" + item.Value);
        }

        // get value based on the key
        string s = employees[101];
        Console.WriteLine("\nvalue at 101:" + s);

        // keys
        Dictionary<int, string>.KeyCollection keys = employees.Keys;
        Console.WriteLine("\nkeys:");
        foreach (int item in keys)
        {
            Console.WriteLine(item);
        }

        // Duplicate key:exception
        employees.Add(104, "Allen");
        
        // Remove
        employees.Remove(101);
        
        // Contains
        employees.ContainsKey(101);
        employees.ContainsValue("Allen");
        
        // Clear
        employees.Clear();
        
        


    }
}